<!-- 公共文件 start -->
@extends('admin.public.base')
<!-- 公共文件 end -->
<style>
    table th {
        min-width: 10px !important;
    }
</style>
@section('content')
    <div class="x-nav">
    <span class="layui-breadcrumb mbx_fl_10">
        <a href="">首页</a>
        <a href="">系统设置</a>
        <a><cite>广告管理</cite></a>
    </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
           onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <form class="layui-form layui-col-space5">
                            <div class="layui-inline layui-show-xs-block">
                                <input type="text" name="title" placeholder="标题" autocomplete="off" value="{{ $param['title'] }}" class="layui-input">
                            </div>
                            <div class="layui-inline layui-show-xs-block">
                                <button class="layui-btn" lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i>
                                </button>
                            </div>
                        </form>
                    </div>
                    <div class="layui-card-header">
                        {{--<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>--}}
                        <button class="layui-btn" onclick="xadmin.open('添加信息','/admin/system/adEdit',800,600)"><i
                                class="layui-icon"></i>添加
                        </button>
                    </div>
                    <div class="layui-card-body layui-table-body layui-table-main">
                        <table class="layui-table" lay-even lay-skin="nob">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>标题</th>
                                <th>分类名称</th>
                                <th>广告图片</th>
                                <th>链接地址</th>
                                <th>状态</th>
                                <th>添加时间</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach( $data as $item)
                                <tr>
                                    <td>{{ $item['id'] }}</td>
                                    <td>{{ $item['title'] }}</td>
                                    <td>{{ $item['cate_name'] }}</td>
                                    <td><img src="{{ $item['image'] }}" alt="广告图" style="width: 120px; height: 70px;"></td>
                                    <td>{{ $item['url'] }}</td>
                                    <td>{{ $item['status'] }}</td>
                                    <td>{{ $item['created_at'] }}</td>
                                    <td class="td-manage">
                                        <a class="layui-btn layui-btn-xs"
                                           onclick="xadmin.open('编辑','/admin/system/adEdit?id={{ $item['id'] }}',800,600)"
                                           href="javascript:;">编辑</a>
                                        <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="confirm_del(this,{{ $item['id'] }})">删除</a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="layui-card-body ">
                        <div class="page">
                            {{ $data->links('admin/public/page') }}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>
        layui.use(['laydate', 'form'], function () {
            var laydate = layui.laydate;
            var form = layui.form;

            // 监听全选
            form.on('checkbox(checkall)', function (data) {

                if (data.elem.checked) {
                    $('tbody input').prop('checked', true);
                } else {
                    $('tbody input').prop('checked', false);
                }
                form.render('checkbox');
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#start', //指定元素
                type: 'datetime'
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end', //指定元素
                type: 'datetime'
            });

        });


        /*删除*/
        function confirm_del(obj, id) {
            layer.confirm('确认要删除吗？', function (index) {
                console.log(id);
                //发异步删除数据
                $.ajax({
                    type: 'POST',
                    url: '/admin/system/adDel?id=' + id,
                    dataType: 'json',
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    },
                    success: function (data) {
                        // console.log(data);
                        if (data.code == 1) {
                            $(obj).parents("tr").remove();
                            layer.msg('已删除!', {icon: 1, time: 1000});
                        } else {
                            layer.alert(data.msg)
                        }
                    },
                    error: function (xhr, type) {
                        alert('Ajax error!')
                    }
                });

            });
        }
    </script>

@endsection
